#ifndef __RF_RECEIVE_H__
#define __RF_RECEIVE_H__

#include "typedef.h"

#ifdef _12F629
    #define RF_TRIS             TRISIO2
    #define RF_PULLUP           WPU2
    #define RF_INT_ANYCHANGE    IOCB2
    #define RF                  GPIO2
#endif
#ifdef _12F683
    #define RF_TRIS             TRISIO4
    #define RF_PULLUP           WPU4
    #define RF_INT_ANYCHANGE    IOC4
    #define RF                  GP4
#endif

#define NUMBER_RF_BIT           12          //12 bit 3 trang thai
#define RF_ADDR_STORE_LOCK      0
#define RF_ADDR_STORE_UNLOCK    3
#define RF_ADDR_STORE_BELL      6
#define DEBUG_EPPROM            9
#define TIMEOUT_RF              (300/SYSTEM_TICK_PERIOD)         //khoang 300ms

#define start_timer1()      TMR1 = 0; TMR1ON = 1
#define reset_timer1()      TMR1 = 0;
#define stop_timer1()       TMR1ON = 0
#define get_timer1()        (TMR1)

#define STATE_NORMAL   0
#define STATE_LEARN    1

#define BIT_CODE_FILTER 0xF0
#define BIT_CODE_MARK   0x0F
#define LOCK_CODE       0x08
#define UNLOCK_CODE     0x02
#define BELL_CODE       0x04

extern U8 s_RFSysnBitTimeout;
extern U8 s_BitCode;
extern U8 s_pRFIncome[3];
extern U8 s_pRFCode[5][3];
extern U8 s_pRFCodeCnt;
extern bit s_ReceiveFlag;

void RF_InitReset(void);
void RF_EraseAllRFCode (void);
void RF_SaveAllRFCode(void);
bool RF_IsExist(void);
void RF_GetReceiveCode(void);
bool RF_receive( void );


#endif  //__RF_RECEIVE_H__